package cc.spider.web.fetcher;


import cc.spider.core.IFetcher;
import cc.spider.core.IFetcherListener;
import cc.spider.model.GlobalDefaultData;
import cc.spider.model.ResultInfo;
import cc.spider.model.TaskInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class Fetcher implements IFetcher {
    private Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public void fetch(TaskInfo taskInfo, GlobalDefaultData defaultData, IFetcherListener fetcherListener) {
        if (fetcherListener == null) {
            fetcherListener = new IFetcherListener() {
                @Override
                public void success(TaskInfo taskInfo, ResultInfo resultInfo) {
                    logger.debug("fetch success");
                }

                @Override
                public void fail(TaskInfo taskInfo, ResultInfo resultInfo) {
                    logger.debug("fetch fail");
                }
            };
        }
        executeFetch(taskInfo, defaultData, fetcherListener);
    }

    protected abstract void executeFetch(TaskInfo request, GlobalDefaultData defaultData, IFetcherListener fetcherListener);
}
